package com.cratos.xxgram.platf.sysnotice;

import javax.persistence.*;
import org.redkale.convert.json.*;
import org.redkale.util.Comment;
import org.redkale.util.Reproduce;

import com.cratos.xxgram.platf.base.BaseEntity;
import com.cratos.xxgram.platf.message.MessageRecord;
import com.cratos.xxgram.platf.message.MessageRecordHis;

/**
 *
 * @author fk
 */
@Table(comment = "系统公告")
public class SystemNotice extends BaseEntity {

	@Comment("历史消息存储 便于oss 查询")
    private static final Reproduce<SystemUserNotice, SystemNotice> systemUserNoticeCoper = Reproduce.create(SystemUserNotice.class, SystemNotice.class);
 
    @Id
    @Column(length = 128, comment = "系统公告id ‘createuserid + time36’")
    private String sysnoticeid = "";

    @Column(length = 64, comment = "通知标题")
    private String title = "";

    @Column(comment = "通知 对象  1 2 4 （1 新用户 2 老用户 4 全员)")
    private short noticetarget;

    @Comment("新用户")
    public static final short USER_CYCLE_NEW = 1;
    
    @Comment("老用户")
    public static final short USER_CYCLE_OLD = 2;
    
    @Comment("所有用户")
    public static final short USER_CYCLE_All = 4;
    
    @Column(length = 2000, comment = "通知内容")
    private String content = "";

    public static final short OPEN_STATUS = 10;
    
    public static final short CLOSE_STATUS = 20;
    
    @Column(comment = "10 开启 20 关闭")
    private short status = 10;

    public boolean isOpenStatus() {
    	return status == OPEN_STATUS;
    }
    
    public boolean isCloseStatus() {
    	return status == CLOSE_STATUS;
    }
    @Comment("新用户")
    public boolean isNewUser() {
    	return this.getNoticetarget() == USER_CYCLE_NEW;
    }
    
    @Comment("老用户")
    public boolean isOldUser() {
    	return this.getNoticetarget() == USER_CYCLE_OLD;
    }
    @Comment("全员")
    public boolean isAllUser() {
    	return this.getNoticetarget() == USER_CYCLE_All;
    }
    @Column(updatable = false, comment = "创建时间")
    private long createtime;

    public void setSysnoticeid(String sysnoticeid) {
        this.sysnoticeid = sysnoticeid;
    }

    public String getSysnoticeid() {
        return this.sysnoticeid;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return this.title;
    }

    public void setNoticetarget(short noticetarget) {
        this.noticetarget = noticetarget;
    }

    public short getNoticetarget() {
        return this.noticetarget;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getContent() {
        return this.content;
    }

    public void setStatus(short status) {
        this.status = status;
    }

    public short getStatus() {
        return this.status;
    }

    public void setCreatetime(long createtime) {
        this.createtime = createtime;
    }

    public long getCreatetime() {
        return this.createtime;
    }

    /**
     * 接收用户 
     * @param userid
     * @return
     */
    public SystemUserNotice copySystemUserNotice(int userid) {
    	SystemUserNotice notice = systemUserNoticeCoper.apply(new SystemUserNotice(), this);
    	notice.setSysusernoticeid(notice.getSysnoticeid() + "-" + userid);
    	notice.setUserid(userid);
    	return notice;
    }
    @Override
    public String toString() {
        return JsonConvert.root().convertTo(this);
    }
}
